﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using KPIS.GERP.Models.Class;

namespace KPIS.GERP.Models.HRM
{
    [Table("hrm_ps_employees"), DataContract]
    public class Employee
    {
        public Employee()
        {

        }

        [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [DataMember, Display(Name = "EmpId", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("emp_seq")]
        public int EmpId { get; set; }

        [CustomRequired]
        [ForeignKey("MasGender")]
        [DataMember, Display(Name = "GenderId", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("gender_seq")]
        public int? GenderId { get; set; }

        [CustomRequired]
        [ForeignKey("MasNamePrefix")]
        [DataMember, Display(Name = "NamePrefixId", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("name_prefix_seq")]
        public int? NamePrefixId { get; set; }

        [CustomRequired]
        [DataMember, Display(Name = "FirstName", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("first_name")]
        public string FirstName { get; set; }

        [CustomRequired]
        [DataMember, Display(Name = "LastName", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("last_name")]
        public string LastName { get; set; }

        [DataMember, Display(Name = "FirstNameEng", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("first_name_eng")]
        public string FirstNameEng { get; set; }

        [DataMember, Display(Name = "LastNameEng", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("last_name_eng")]
        public string LastNameEng { get; set; }

        [DataMember, Display(Name = "NickName", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("nick_name")]
        public string NickName { get; set; }

        [ForeignKey("MasReligion")]
        [DataMember, Display(Name = "ReligionId", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("religion_seq")]
        public int? ReligionId { get; set; }

        [ForeignKey("RaceMasNationality")]
        [DataMember, Display(Name = "RaceNationalId", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("race_nat_seq")]
        public int? RaceNationalId { get; set; }

        [ForeignKey("MasNationality")]
        [DataMember, Display(Name = "NationalId", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("nat_seq")]
        public int? NationalId { get; set; }

        [CustomRequired]
        [DisplayFormat(DataFormatString = "0:dd/MM/yyyy")]
        [DataMember, Display(Name = "BirthDate", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("birth_date")]
        public DateTime? BirthDate { get; set; }

        [DataMember, Display(Name = "BloodGroup", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("blood_group_seq")]
        public int? BloodGroup { get; set; }

        [CustomRequired]
        [MaxLength(13, ErrorMessageResourceName = "CitizenMax", ErrorMessageResourceType = typeof(Resources.EmployeeResource))]
        [MinLength(13, ErrorMessageResourceName = "CitizenMin", ErrorMessageResourceType = typeof(Resources.EmployeeResource))]
        [DisplayFormat(DataFormatString = "#,##0.00# ฿")]
        [DataMember, Display(Name = "Citizen", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("citizen")]
        public string Citizen { get; set; }

        [MaxLength(13, ErrorMessageResourceName = "TaxPayerMax", ErrorMessageResourceType = typeof(Resources.EmployeeResource))]
        [MinLength(13, ErrorMessageResourceName = "TaxPayerMin", ErrorMessageResourceType = typeof(Resources.EmployeeResource))]
        [DataMember, Display(Name = "TaxPayer", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("tax_payer")]
        public string TaxPayer { get; set; }

        [MaxLength(13, ErrorMessageResourceName = "SocialMax", ErrorMessageResourceType = typeof(Resources.EmployeeResource))]
        [MinLength(13, ErrorMessageResourceName = "SocialMin", ErrorMessageResourceType = typeof(Resources.EmployeeResource))]
        [DataMember, Display(Name = "Social", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("social")]
        public string Social { get; set; }

        [MaxLength(13, ErrorMessageResourceName = "OfficialMax", ErrorMessageResourceType = typeof(Resources.EmployeeResource))]
        [MinLength(13, ErrorMessageResourceName = "OfficialMin", ErrorMessageResourceType = typeof(Resources.EmployeeResource))]
        [DataMember, Display(Name = "Official", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("official")]
        public string Official { get; set; }

        #region Work

        [ForeignKey("MasEmployeeType")]
        [DataMember, Display(Name = "EmpTypeId", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("emp_type_seq")]
        public int? EmpTypeId { get; set; }

        [ForeignKey("MasClass")]
        [DataMember, Display(Name = "ClassId", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("class_seq")]
        public int? ClassId { get; set; }

        [DataMember, Display(Name = "SalaryLevelId", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("salary_level_seq")]
        public int? SalaryLevelId { get; set; }

        [DataMember, Display(Name = "Salary", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("salary")]
        public decimal? Salary { get; set; }

        [ForeignKey("Position")]
        [DataMember, Display(Name = "PosId", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("pos_seq")]
        public int? PosId { get; set; }

        [ForeignKey("ExecutivePosition")]
        [DataMember, Display(Name = "ExecPosId", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("exec_pos_seq")]
        public Nullable<int> ExecPosId { get; set; }

        [ForeignKey("JobSite")]
        [DataMember, Display(Name = "WorkingJobSiteId", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("working_job_site_seq")]
        public int? WorkingJobSiteId { get; set; }

        [DisplayFormat(DataFormatString = "0:dd/MM/yyyy")]
        [DataMember, Display(Name = "AdmittedDate", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("date_admitted")]
        public DateTime? AdmittedDate { get; set; }

        [DisplayFormat(DataFormatString = "0:dd/MM/yyyy")]
        [DataMember, Display(Name = "WorkStartDate", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("date_work_start")]
        public DateTime? WorkStartDate { get; set; }

        [DisplayFormat(DataFormatString = "0:dd/MM/yyyy")]
        [DataMember, Display(Name = "QuitDate", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("date_quit")]
        public DateTime? QuitDate { get; set; }

        [DisplayFormat(DataFormatString = "0:dd/MM/yyyy")]
        [DataMember, Display(Name = "ProbationEndDate", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("probation_date_end")]
        public DateTime? ProbationEndDate { get; set; }

        [DisplayFormat(DataFormatString = "0:dd/MM/yyyy")]
        [DataMember, Display(Name = "DeathDate", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("death_date")]
        public DateTime? DeathDate { get; set; }

        [DisplayFormat(DataFormatString = "0:dd/MM/yyyy")]
        [DataMember, Display(Name = "LatestPositionDate", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("date_latest_pos")]
        public DateTime? LatestPositionDate { get; set; }

        [DisplayFormat(DataFormatString = "0:dd/MM/yyyy")]
        [DataMember, Display(Name = "LatestClassDate", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("date_latest_class")]
        public DateTime? LatestClassDate { get; set; }

        [DisplayFormat(DataFormatString = "0:dd/MM/yyyy")]
        [DataMember, Display(Name = "LatestWorkingJobSiteDate", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("date_latest_working_job_site")]
        public DateTime? LatestWorkingJobSiteDate { get; set; }

        #endregion

        #region Family

        [ForeignKey("MasMaritalStatus")]
        [DataMember, Display(Name = "MaritalStatId", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("mar_stat_seq")]
        public int? MaritalStatusId { get; set; }

        #endregion

        [DataMember, Display(Name = "ImageUnique", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("image_unique")]
        public string ImageUnique { get; set; }

        [ForeignKey("MasEmployeeStatus")]
        [DataMember, Display(Name = "EmpStatusId", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("emp_status_seq")]
        public int? EmpStatusId { get; set; }

        [DataMember, Display(Name = "Remarks", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("remarks")]
        public string Remarks { get; set; }
        
        [DataMember]
        [Column("is_mock_employee")]
        public bool IsMockEmployee { get; set; }

        [EnumDataType(typeof(SYS.RecordStatus.EnumRecordStatus))]
        [DataMember, Display(Name = "enumRecordStatus", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("record_status")]
        public string RecordStatus { get; set; }

        [Column("created_by")]
        public int? CreatedBy { get; set; }
        [Column("created_when")]
        public DateTime? CreatedWhen { get; set; }
        [Column("updated_by")]
        public int? UpdatedBy { get; set; }
        [Column("updated_when")]
        public DateTime? UpdatedWhen { get; set; }

        [DataMember]
        public virtual MasNamePrefix MasNamePrefix { get; set; }

        [DataMember]
        public virtual MasGender MasGender { get; set; }

        [DataMember]
        public virtual MasReligion MasReligion { get; set; }

        [DataMember]
        public virtual MasNationality RaceMasNationality { get; set; }

        [DataMember]
        public virtual MasNationality MasNationality { get; set; }

        [DataMember]
        public virtual MasEmployeeType MasEmployeeType { get; set; }

        [DataMember]
        public virtual MpClass MasClass { get; set; }

        [DataMember]
        public virtual Position Position { get; set; }

        [DataMember]
        public virtual HRM.JobSite JobSite { get; set; }

        [DataMember]
        public virtual HRM.PsEmployeeStatus MasEmployeeStatus { get; set; }

        [DataMember]
        public virtual ExecutivePosition ExecutivePosition { get; set; }

        [DataMember]
        public virtual MasMaritalStatus MasMaritalStatus { get; set; }


        [Display(Name = "FullName", ResourceType = typeof(Resources.EmployeeResource))]
        [Column("full_name")]
        public string FullName
        {
            get
            {
                return String.Format("{0}{1} {2}", MasNamePrefix == null ? String.Empty : MasNamePrefix.Name, FirstName, LastName).Trim();
            }
        }
    }
}
